home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / printing / scalable postscript pict / scalable.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.3 KB  |  141 lines

  1. /*
  2.     File:        Template.c
  3.  
  4.     Contains:    Scalable PostScript PICT:  Shows how you can use the PostScript clip in
  5.                 combination with the QuickDraw clipping region to make PostScript code that
  6.                 scales at run-time.  Has some limitations, but a useful technique.
  7.  
  8.  
  9.     Written by:     
  10.  
  11.     Copyright:    Copyright © 1984-1999 by Apple Computer, Inc., All Rights Reserved.
  12.  
  13.                 You may incorporate this Apple sample source code into your program(s) without
  14.                 restriction. This Apple sample source code has been provided "AS IS" and the
  15.                 responsibility for its operation is yours. You are not permitted to redistribute
  16.                 this Apple sample source code as "Apple sample source code" after having made
  17.                 changes. If you're going to re-distribute the source, we require that you make
  18.                 it clear in the source that the code was descended from Apple sample source
  19.                 code, but that you've made changes.
  20.  
  21.     Change History (most recent first):
  22.                 7/26/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  23.                 
  24.  
  25. */
  26.  
  27.  
  28. #include "PrintComments.h"
  29. #include<Quickdraw.h>
  30. #include<Fonts.h>
  31. #include<Windows.h>
  32. #include<TextEdit.h>
  33. #include<Dialogs.h>
  34. #include<Menus.h>
  35. #include<Scrap.h>
  36.  
  37. PicHandle DoPicture(void);
  38. Handle StuffInHandle(const Str255 theString);
  39.  
  40. /*------ main ----------------------------------------------------------------------------*/
  41.  
  42. PicHandle myPicture;
  43.  
  44. void main()
  45.  
  46. {
  47.  
  48.     GrafPort myPort;
  49.  
  50.  
  51.     InitGraf(&qd.thePort);
  52.     OpenPort(&myPort);
  53.     InitFonts();
  54.     InitWindows();
  55.     InitMenus();
  56.     TEInit();
  57.     InitDialogs(nil);
  58.     InitCursor();
  59.  
  60.       myPicture = DoPicture();                   // make and publish our picture
  61.  
  62. } /* main */
  63.  
  64.  
  65.  
  66.  
  67. /*------ DoPicture ----------------------------------------------------------------------*/
  68.  
  69. PicHandle DoPicture (void)
  70.  
  71. {
  72.     Rect myRect;
  73.     PicHandle thePicHandle;
  74.     GrafPort myPort;
  75.     long scrapResult;
  76.     unsigned long thePictureSize;
  77.     short theFont, textSize = 14;
  78.     Handle myHandle;
  79.     
  80.     const Str255 myString = 
  81.          "\pclippath pathbbox 4 copy moveto lineto 4 1 roll exch moveto exch lineto stroke\r";
  82.  
  83.     OpenPort(&myPort);
  84.     SetRect(&myRect,0,0,200,200);
  85.     thePicHandle = OpenPicture(&myRect);
  86.     ClipRect(&myRect);
  87.     
  88.     MoveTo(22,22);
  89.     LineTo(55,55);
  90.     LineTo(58,22);
  91.     LineTo(22,58);
  92.     
  93.     GetFNum ("\pTimes", &theFont);
  94.     TextFont (theFont);
  95.     TextSize (textSize);
  96.     
  97.     SetRect(&myRect,50,50,100,150);
  98.     ClipRect(&myRect);
  99.     
  100.     MoveTo(0,0);
  101.     LineTo(0,0);                // flush the QuickDraw changes to the clip
  102.     
  103.     PicComment(PostScriptBegin,0,NULL);
  104.     myHandle = StuffInHandle(myString);
  105.     PicComment(PostScriptHandle,myString[0],myHandle);
  106.     DisposeHandle(myHandle);
  107.     PicComment(PostScriptEnd,0,NULL); 
  108.  
  109.     SetRect(&myRect,0,0,200,200);
  110.     ClipRect(&myRect);
  111.     
  112.     MoveTo(100,50);
  113.     DrawString("\pA wonderful test");
  114.     
  115.     ClosePicture();
  116.     ClosePort(&myPort);
  117.     
  118.     thePictureSize = GetHandleSize((Handle)thePicHandle);
  119.  
  120.     ZeroScrap();
  121.     HLock((Handle)thePicHandle);
  122.     scrapResult = PutScrap(GetHandleSize((Handle)thePicHandle),'PICT',StripAddress(*thePicHandle));
  123.     HUnlock((Handle)thePicHandle);
  124.  
  125.     KillPicture(thePicHandle);            // don't forget to clean up after yourself
  126.     
  127.     return thePicHandle;
  128. }  /* InitPicture */
  129.  
  130. /*------ StuffInHandle ----------------------------------------------------------------------*/
  131.  
  132.  
  133. Handle StuffInHandle(const Str255 theString)
  134. {
  135.     Handle theHandle = NewHandle(theString[0]);
  136.     HLock(theHandle);
  137.     BlockMove((Ptr)&theString[1],*theHandle,theString[0]);
  138.     HUnlock(theHandle);
  139.     return(theHandle);
  140. }
  141.